package com.sh.dc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sh.dc.common.pojo.query.ProductSourcePageQuery;
import com.sh.dc.entity.Operator;
import com.sh.dc.entity.ProductSource;
import com.sh.dc.mapper.ProductSourceMapper;
import com.sh.dc.service.IProductSourceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.micrometer.common.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 制品源表 服务实现类
 * </p>
 *
 * @author zhenlan
 * @since 2024-07-10
 */
@Service
public class ProductSourceServiceImpl extends ServiceImpl<ProductSourceMapper, ProductSource> implements IProductSourceService {

    @Autowired
    private ProductSourceMapper productSourceMapper;

    @Override
    public IPage<ProductSource> queryProductSourcePage(ProductSourcePageQuery query) {
        Page<ProductSource> page = new Page<>(query.getPageNum(), query.getPageSize());
        QueryWrapper<ProductSource> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(query.getName())) {
            queryWrapper.like("name", query.getName());
        }
        if (StringUtils.isNotBlank(query.getNameEn())) {
            queryWrapper.like("name_en", query.getNameEn());
        }
        if (StringUtils.isNotBlank(query.getRegistryOrNamespace())) {
            queryWrapper.like("registry", query.getRegistryOrNamespace()).or().like("namespace", query.getRegistryOrNamespace());
        }
        if (StringUtils.isNotBlank(query.getCreateBy())) {
            queryWrapper.eq("create_by", query.getCreateBy());
        }
        return productSourceMapper.selectPage(page, queryWrapper);
    }
}
